//
//  SailorMessageViewController.m
//  shuiyun
//
//  Created by 徐双 on 2017/9/8.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "SailorMessageViewController.h"
#import "BoatBeizhuViewCell.h"
#import "BoatDetailViewCell.h"
#import "SaliorMessageViewCell.h"
#import "UIImageView+WebCache.h"

@interface SailorMessageViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView * tableView;


@property(nonatomic,strong)NSMutableDictionary * dict;

@property(nonatomic,strong) UILabel * label2;

@end

@implementation SailorMessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpSaliorMessage];
    
    [self setTitle:@"船员信息"];
    
    [self setUpTableview];
    
    [self setUpLastView];
    
}

-(void)setUpSaliorMessage{

    _dict = [NSMutableDictionary dictionary];
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    [productParams setValue:token forKey:@"token"];
    NSString * userid = [PublicFunction getConfigWithKey:@"userid"];
    [productParams setValue:userid forKey:@"userid"];
    [productParams setValue:self.idStr forKey:@"id"];
    
    [[MNetworkHandler sharedInstance]conURL:HomeQiuzhiDetail  networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        NSLog(@"%@", returnData);
        NSLog(@"%@", productParams);
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
            _dict = [returnData objectForKey:@"data"];
            NSLog(@"!!!!!!!!!!!!!!!%@",_dict);
            
            self.label2.text = [_dict objectForKey:@"newstime"];
            
            [self.tableView reloadData];
            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];
}


-(void)setUpLastView{
    
    UILabel * label1 = [[UILabel alloc] init];
    [self.view addSubview:label1];
    label1.text = @"发布信息:";
    label1.font = [UIFont systemFontOfSize:17];
    label1.textColor = [UIColor colorWithRed:129/255.0f green:129/255.0f blue:129/255.0f alpha:1];
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view).with.offset(80);
        make.bottom.equalTo(self.view).with.offset(-5);
        make.width.offset(80);
        make.height.offset(25);
        
    }];
    
    UILabel * label2 = [[UILabel alloc] init];
    [self.view addSubview:label2];
    self.label2 = label2;
    label2.text = @"2017/07/27 15: 33";
    label2.font = [UIFont systemFontOfSize:17];
    label2.textColor = [UIColor colorWithRed:129/255.0f green:129/255.0f blue:129/255.0f alpha:1];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(label1.mas_right).with.offset(5);
        make.centerY.equalTo(label1.mas_centerY);
        make.width.offset(400);
        make.height.offset(25);
        
    }];
    
}

-(void)setUpTableview{
    
    
    //初始化tableView
    
    self.tableView = [[UITableView alloc] init];
    self.tableView.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 64 - 25);
    
    
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    
    
    self.tableView.estimatedRowHeight = 800;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //   self.tableView.estimatedRowHeight = 400;
    self.tableView.separatorStyle = UITableViewCellAccessoryNone;//去掉分割线
    
    
    [self.view addSubview:self.tableView];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"BoatBeizhuViewCell" bundle:nil] forCellReuseIdentifier:@"BoatBeizhuViewCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"BoatDetailViewCell" bundle:nil] forCellReuseIdentifier:@"BoatDetailViewCell"];
    
    
    [self.tableView registerNib:[UINib nibWithNibName:@"SaliorMessageViewCell" bundle:nil] forCellReuseIdentifier:@"SaliorMessageViewCell"];

}

#pragma mark - ---------- Section的数量 ----------
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

#pragma mark - ---------- 每个Section的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        
        return 0;
    }else if(section == 1){
        
        return 10;
        
    }else{
    
        return 10;
    }
}



#pragma mark - ---------- Cell的数量 ----------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        
        return 1;
    }else if(section == 1){
        
        return 2;
        
    }else{
    
        return 1;
    }
    
    
}

#pragma mark - ---------- 每个Cell的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        
        return 100;
    }else if(indexPath.section == 1){
        
        return 50;
    }else{
    
        return UITableViewAutomaticDimension;
               
    }
    
}

#pragma mark - ---------- 每个Cell的内容 ----------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if(indexPath.section == 0){
        
        SaliorMessageViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SaliorMessageViewCell"];
        cell.selectionStyle = UITableViewCellEditingStyleNone;
        
        cell.nameLabel.text = [_dict objectForKey:@"username"];
        
        cell.titleLabel.text = [_dict objectForKey:@"title"];
        
        
        NSURL * url = [NSURL URLWithString:@"titlepic"];
     
        [cell.iconImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"添加头像"]];
        
        
        return cell;
        
    }else  if (indexPath.section == 1) {
        
        BoatDetailViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"BoatDetailViewCell"];
        cell.selectionStyle = UITableViewCellEditingStyleNone;
        if (indexPath.row == 0) {
            
            cell.nameLabel.text = @"联系人";
            cell.contentLabel.text = [_dict objectForKey:@"q_xinnin"];
        }else {
            
            cell.nameLabel.text = @"联系电话";
            cell.contentLabel.text = [_dict objectForKey:@"q_tel"];
        }
        return cell;
        
    }else{
        
        BoatBeizhuViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"BoatBeizhuViewCell"];
        cell.selectionStyle = UITableViewCellEditingStyleNone;
        
        cell.beizhuLabel.text = @"工作经历";
        cell.beizhuContentLabel.text = [_dict objectForKey:@"q_conter"];
        
        [cell.beizhuContentLabel sizeToFit];
        
        return cell;
        
        
    }
}
@end
